package config

import (
	"github.com/spf13/viper"
)

const DORMITORY_CONFIG_PATH = "."

//init viper config
func Init() error {
	viper.SetConfigName("dormitory_data")
	viper.SetConfigType("json")
	viper.AddConfigPath(DORMITORY_CONFIG_PATH)

	err := viper.ReadInConfig() // Find and read the config file
	if err != nil {            // Handle errors reading the config file
		return err
	}

	return nil
}

//中文楼栋名与宿舍转宿舍ID (榕园五栋, 531) -> 290531
func CHNBuildingAndRoomNameToRoomId(buildingName string, roomId string) (id string, e error) {
	id = GetBuildingId(buildingName)
	id = id + "0" + roomId
	return
}

//通过中文名楼栋名获取楼栋ID
func GetBuildingId(roomName string) (buildingId string) {
	buildingId = viper.GetString(roomName)
	return
}
